<template>
  <view class="wraps">
    <view class="content">
      <view class="nodate" v-if="listLoading">
        <up-loading-icon></up-loading-icon>
      </view>
      <view v-if="state.taskList && state.taskList.length > 0">
        <indexCardRecord :message="messageObj" @reload="reload"></indexCardRecord>
      </view>
      <view class="nodate" v-else>
        <img class="img" src="https://ainengli.meilianshuke.com/jkhx/noData.png" alt="" />
        <view class="nodate_text">
          <text class="name">暂无数据</text>
        </view>
      </view>
    </view>
    <up-modal
      :show="state.deleteShow"
      :title="'提示'"
      :closeOnClickOverlay="true"
      :showCancelButton="true"
      :confirmColor="'#FF503D'"
      @confirm="deleteSignsInfo"
      @close="cancel"
      @cancel="cancel"
    >
      <view
        style="width: 100%; font-size: 30rpx; font-weight: 400; color: #4e5969; text-align: center"
        >确认要删除该条记录吗?</view
      >
    </up-modal>
  </view>
</template>

<script setup lang="ts">
import { reactive, computed, ref, watch } from 'vue'
import { healthInfoMapList, healthInfoUpdate } from '@/api/hmm'
import { onLoad, onShow, onReachBottom } from '@dcloudio/uni-app'
import { getNewDetail, getWaterSleepDetail, signsInfoDelete } from './healthPortrait.api'
import { parseTime } from '@/utils/tools'
import slideRule from './components/slideRule'
import MyLoadmore from '../../../components/MyLoadmore/MyLoadmore.vue'
import indexCardRecord from './components/indexCardRecord'
import { saveNewIndicator, getSignsList, saveReport } from './healthPortrait.api'
const state = reactive({
  type: '',
  filtrate: {
    //请求参数
    size: 20, // 条数
    num: 1 // 页数
  },
  taskList: [], //数据
  show: false,
  inputValue: '',
  maxNum: 100, //最多输入字数
  getObj: {},
  slideRuleType: '',
  loadstatus: 'nomore',
  slideRuleTypeDefault: false,
  tabkeyboardShow: true,
  slideRuleShow: true,
  isClick: false,
  showTest: false,
  deleteShow: false,
  userInfo: {},
  bloodSugarActive: 0,
  current: 60, //刻度指向的位置
  maxValue: 150,
  ruleType: 'cm',
  healthList: {},
  datetime: '',
  minDate: 0,
  time: '',
  datetimeNew: '',
  checkRulesType: '', //判断患病类型
  wakeupDate: '',
  sleepDate: ''
})
const updateId = ref('')
const listLoading = ref(false)
const abnormalShow = ref<boolean>(false)
const waterShow = ref<boolean>(false)
const waterShowIndex = ref<number>(0)
const sleepTimeType = ref('')
const measurementShow = ref(false)
const show = ref(false)
const showSleep = ref(false)
const dateShow = ref(false)
const dateSleepShow = ref(false)
const userInfo = ref<any>({})
const messageObj = ref<any>({
  taskList: [],
  type: '',
  loadstatus: 'loadmore'
})
const empi = ref<string>('')
let scrollLeft: string = '0rpx'
const editWaterData = ref({
  id: 0,
  collectTime: '',
  dataSource: '',
  paramValue: '',
  paramKey: '',
  empi: ''
})

const message = ref({
  init: 50,
  currentScore: 50,
  maxValue: 100,
  name: '',
  unit: ''
})
const messageWeight = ref({
  init: 50,
  currentScore: 100,
  maxValue: 150,
  name: '',
  unit: ''
})
const messageThree = ref({
  init: 50,
  currentScore: 100,
  maxValue: 150,
  name: '',
  unit: ''
})

const messageFour = ref({
  init: 50,
  currentScore: 100,
  maxValue: 150,
  name: '',
  unit: ''
})
const measurementValue = ref({
  height: 0, //身高
  weight: 0, //体重
  pulse: 0, //脉搏,
  fourValue: 0 // 第四组值
})
const options = reactive([
  {
    text: '删除',
    style: {
      backgroundColor: '#ff503d'
    }
  }
])
const swipeRef = ref()
const deleteIndex = ref(0)
const bloodSugarList = reactive([
  {
    name: '早起',
    title: '空腹',
    value: 'empty_stomach'
  },
  {
    name: '早餐后',
    title: '2小时',
    value: 'breakfast_after_2'
  },
  {
    name: '午餐前',
    title: '-',
    value: 'lunch_before'
  },
  {
    name: '午餐后',
    title: '2小时',
    value: 'lunch_after_2'
  },
  {
    name: '晚餐前',
    title: '-',
    value: 'dinner_before'
  },
  {
    name: '晚餐后',
    title: '2小时',
    value: 'dinner_after_2'
  },
  {
    name: '睡前',
    title: '-',
    value: 'sleep_before'
  }
])

onLoad((option: any) => {
  if (option.type) {
    if (option.type == 'blood_pressure') {
      state.type = 'sbp'
    } else if (option.type == 'heart') {
      state.type = 'heart_rate'
    } else if (option.type == 'blood_oxygen') {
      state.type = 'spo2'
    } else if (option.type == 'BMI') {
      state.type = 'bmi'
    } else {
      state.type = option.type
    }
    messageObj.value.type = state.type
  }
  userInfo.value = uni.getStorageSync('userInfo')
    ? JSON.parse(uni.getStorageSync('userInfo')).patientInfo
    : {}

  empi.value = option.empi ? option.empi : userInfo.value.empi
})
onReachBottom(() => {
  if (state.loadstatus != 'nomore') {
    loadMoreData()
  }
})
onShow(() => {
  waterShow.value = false
  scrollLeft = '0rpx'
  state.taskList = []
  messageObj.value.taskList = []
  init()
})

watch(
  () => state.inputValue,
  (newVal, oldVal) => {
    if (newVal && newVal.length > 100) {
      state.inputValue = newVal.substring(0, 100)
    }
  },
  {
    immediate: true
  }
)
const init = () => {
  if (
    state.type == 'blood_ketone' ||
    state.type == 'uric_acid' ||
    state.type == 'blood_fat' ||
    state.type == 'liver_function' ||
    state.type == 'blood_sugar'
  ) {
    getNewList()
  } else if (state.type == 'water' || state.type == 'sleep') {
    getWaterSleepList()
  } else {
    getList()
  }
}

// 获取数据
const getList = () => {
  if (state.taskList.length == 0) {
    listLoading.value = true
  }
  state.loadstatus = 'loading'
  messageObj.value.loadstatus = 'loading'
  const param = {
    empi: empi.value,
    page: state.filtrate.num,
    limit: state.filtrate.size,
    itemList: []
  }
  if (state.type == 'fbg') {
    const obj1 = 'fbg'
    const obj2 = 'pbg'
    param.itemList.push(obj1)
    param.itemList.push(obj2)
  } else {
    param.itemList.push(state.type)
  }
  getSignsList(param).then((res) => {
    listLoading.value = false
    if (res.code == 0) {
      if (res.data && res.data.length > 0) {
        if (state.taskList.length > 0) {
          state.taskList = state.taskList.concat(res.data)
          messageObj.value.taskList = state.taskList
        } else {
          state.taskList = res.data
          messageObj.value.taskList = state.taskList
        }
        if (res.data.length < 20) {
          state.loadstatus = 'nomore'
          messageObj.value.loadstatus = 'nomore'
        } else {
          state.loadstatus = 'loadmore'
          messageObj.value.loadstatus = 'loadmore'
        }
      } else {
        state.loadstatus = 'nomore'
        messageObj.value.loadstatus = 'nomore'
      }
    } else {
      state.filtrate.num--
      state.loadstatus = 'error'
      messageObj.value.loadstatus = 'error'
    }
  })
}
const reload = () => {
  state.filtrate.num++
  getList()
}
const getNewList = () => {
  listLoading.value = true
  state.loadstatus = 'loading'
  messageObj.value.loadstatus = 'loading'
  const param = {
    empi: userInfo.value.empi,
    indicatorKey: state.type
  }
  getNewDetail(param).then((res: any) => {
    listLoading.value = false
    if (res.code == 0) {
      if (res.data && res.data.length > 0) {
        const seenDates = new Set()
        state.taskList = res.data.map((item) => {
          const date = item.report.checkTime.split(' ')[0] // 提取日期部分
          const time = item.report.checkTime
          if (seenDates.has(date)) {
            // 如果日期已出现，隐藏 checkTime
            return { ...item, report: { ...item.report, checkTime: null, realTime: time } }
          } else {
            // 如果日期未出现，保留 checkTime
            seenDates.add(date)
            return item
          }
        })
        messageObj.value.taskList = state.taskList
        if (res.data.length < 20) {
          state.loadstatus = 'nomore'
          messageObj.value.loadstatus = 'nomore'
        } else {
          state.loadstatus = 'loadmore'
          messageObj.value.loadstatus = 'loadmore'
        }
      } else {
        state.taskList = []
        messageObj.value.taskList = []
        state.loadstatus = 'nomore'
        messageObj.value.loadstatus = 'nomore'
      }
    } else {
      state.filtrate.num--
      state.loadstatus = 'error'
      messageObj.value.loadstatus = 'error'
    }
  })
}

const getWaterSleepList = () => {
  listLoading.value = true
  state.loadstatus = 'loading'
  messageObj.value.loadstatus = 'loading'
  const param = {
    empi: userInfo.value.empi,
    itemList: [state.type],
    page: 1,
    limit: 10
  }
  getWaterSleepDetail(param).then((res: any) => {
    listLoading.value = false
    if (res.code == 0) {
      const seenDates = new Set()
      if (res.data && res.data.length > 0) {
        if (state.type == 'sleep') {
          state.taskList = res.data.map((item: any) => {
            const date = item.collectTime.split(' ')[0]
            if (seenDates.has(date)) {
              return {
                ...item,
                collectTime: null,
                paramValue: JSON.parse(item.paramValue)
              }
            } else {
              seenDates.add(date)
              return {
                ...item,
                paramValue: JSON.parse(item.paramValue)
              }
            }
          })
          // 解决IOS下不兼容yyyy-MM-dd格式问题
          state.taskList.forEach((val) => {
            val.paramValue.sleepTime = parseTime(val.paramValue.sleepTime, '{y}/{m}/{d} {h}:{i}')
            val.paramValue.weekupTime = parseTime(val.paramValue.weekupTime, '{y}/{m}/{d} {h}:{i}')
          })
          messageObj.value.taskList = state.taskList
        } else {
          state.taskList = res.data
          messageObj.value.taskList = state.taskList
        }
        if (res.data.length < 20) {
          state.loadstatus = 'nomore'
          messageObj.value.loadstatus = 'nomore'
        } else {
          state.loadstatus = 'loadmore'
          messageObj.value.loadstatus = 'loadmore'
        }
      } else {
        state.taskList = []
        messageObj.value.taskList = []
        state.loadstatus = 'nomore'
        messageObj.value.loadstatus = 'nomore'
      }
    } else {
      state.filtrate.num--
      state.loadstatus = 'error'
      messageObj.value.loadstatus = 'error'
    }
  })
}
const loadMoreData = () => {
  state.filtrate.num++
  getList()
}

const prevent = () => {}
// 获取录入类型名称
const getCheckRulesTypeName = (type: string) => {
  let name: string = ''
  switch (type) {
    case 'BMI':
      name = '体重录入'
      break
    case 'whr':
      name = '腰臀比录入'
      break
    case 'blood_pressure':
      name = '血压录入'
      break
    case 'heart':
      name = '心率录入'
      break
    case 'blood_sugar':
      name = '血糖录入'
      break
    case 'blood_oxygen':
      name = '血氧录入'
      break
    case 'blood_ketone':
      name = '血酮录入'
      break
    case 'uric_acid':
      name = '尿酸录入'
      break
    case 'sleep':
      name = '睡眠录入'
      break
    case 'water':
      name = '饮水录入'
      break
    case 'blood_fat':
      name = '血脂录入'
      break
    case 'liver_function':
      name = '肝功能录入'
      break
    default:
      name = ''
      break
  }
  return name
}
const measurementFun = () => {
  if (
    state.checkRulesType == 'BMI' ||
    state.checkRulesType == 'blood_pressure' ||
    state.checkRulesType == 'blood_sugar'
  ) {
    measurementShow.value = true
    show.value = false
    showSleep.value = false
  }
}
const bloodSugarTab = (item, index) => {
  state.bloodSugarActive = index
}

const timeSleepFun = (date: any, type: string) => {
  sleepTimeType.value = type
  showSleep.value = false
  state.tabkeyboardShow = false
  dateSleepShow.value = true
  // state.datetime = parseTime(date, '{y}-{m}-{d} {h}:{i}')
  state.datetime = new Date(date).getTime()
}
const getMinTime = () => {
  const date = new Date()
  date.setFullYear(new Date().getFullYear())
  date.setMonth(0)
  date.setDate(1)
  date.setHours(0)
  date.setMinutes(0)
  state.minDate = date.getTime()
}
// sleep
// 获取昨天 22:00 的日期时间字符串
const getYesterdayAt2200 = () => {
  const yesterday = new Date()
  yesterday.setDate(yesterday.getDate() - 1)
  yesterday.setHours(22, 0, 0, 0)
  return yesterday.toISOString().split('T')[0] + ' 22:00'
}
const closeSleepDateTime = () => {
  showSleep.value = true
  state.tabkeyboardShow = true
  dateSleepShow.value = false
}
const confirmSleepDateTime = () => {
  showSleep.value = true
  dateSleepShow.value = false
  if (state.datetimeNew) {
    if (sleepTimeType.value == 'sleep') {
      state.sleepDate = state.datetimeNew.replace(/\//g, '-')
    } else {
      state.wakeupDate = state.datetimeNew.replace(/\//g, '-')
    }
  } else {
    if (sleepTimeType.value == 'sleep') {
      state.sleepDate = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}').replace(/\//g, '-')
    } else {
      state.wakeupDate = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}').replace(/\//g, '-')
    }
  }
}
const changeSleepFun = (item) => {
  const data = parseTime(new Date(item.value).getTime(), '{y}-{m}-{d} {h}:{i}')
  state.datetimeNew = data
}
const sure = () => {
  if (state.isClick == true) {
    return false
  }
  uni.showLoading({
    title: '加载中'
  })
  let param = {}
  if (state.checkRulesType == 'BMI') {
    const bmiDate = (
      (measurementValue.value.weight /
        measurementValue.value.height /
        measurementValue.value.height) *
      10000
    ).toFixed(1)
    param = {
      id: updateId.value,
      bmi: bmiDate,
      height: measurementValue.value.height,
      weight: measurementValue.value.weight,
      empi: userInfo.value.empi,
      collectTime: state.time + ':00',
      dataSource: 'MANUAL'
    }
    oldHealthDataUpdate(param)
  } else if (state.checkRulesType == 'whr') {
    const bmiDate = (measurementValue.value.height / measurementValue.value.weight).toFixed(2)
    param = {
      id: updateId.value,
      whr: bmiDate,
      waist: Number(measurementValue.value.height),
      hip: Number(measurementValue.value.weight),
      empi: userInfo.value.empi,
      collectTime: state.time + ':00',
      dataSource: 'MANUAL'
    }
    oldHealthDataUpdate(param)
  } else if (state.checkRulesType == 'blood_pressure') {
    param = {
      id: updateId.value,
      sbp: Number(measurementValue.value.height),
      dbp: Number(measurementValue.value.weight),
      pulseRate: Number(measurementValue.value.pulse),
      empi: userInfo.value.empi,
      collectTime: state.time + ':00',
      dataSource: 'MANUAL'
    }
    oldHealthDataUpdate(param)
  } else if (state.checkRulesType == 'heart') {
    const reg = /^\+?[1-9][0-9]*$/
    if (reg.test(measurementValue.value.height + '')) {
      param = {
        id: updateId.value,
        heartRate: measurementValue.value.height,
        empi: userInfo.value.empi,
        collectTime: state.time + ':00',
        dataSource: 'MANUAL'
      }
      oldHealthDataUpdate(param)
    } else {
      uni.hideLoading()
      uni.showToast({
        title: '请输入正整数',
        icon: 'none'
      })
      return false
    }
  } else if (state.checkRulesType == 'blood_sugar') {
    param = {
      report: {
        reportId: updateId.value,
        empi: userInfo.value.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'blood_sugar'
      },
      details: [
        {
          empi: userInfo.value.empi,
          indicatorKey: bloodSugarList[state.bloodSugarActive].value,
          indicatorValue: Number(measurementValue.value.height),
          parentKey: 'blood_sugar'
        }
      ]
    }
    saveReportData(param)
  } else if (state.checkRulesType == 'blood_oxygen') {
    param = {
      id: updateId.value,
      spo2: Math.round(Number(measurementValue.value.height)),
      empi: userInfo.value.empi,
      collectTime: state.time + ':00',
      dataSource: 'MANUAL'
    }
    oldHealthDataUpdate(param)
  } else if (state.checkRulesType == 'water') {
    param = {
      id: updateId.value,
      paramValue: Math.round(Number(measurementValue.value.height)),
      empi: userInfo.value.empi,
      dataSource: 'MANUAL',
      paramKey: 'water',
      collectTime: state.time + ':00'
    }
    newHealthDateSave(param)
  } else if (state.checkRulesType == 'blood_ketone') {
    param = {
      report: {
        reportId: updateId.value,
        empi: userInfo.value.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'blood_ketone'
      },
      details: [
        {
          empi: userInfo.value.empi,
          indicatorKey: 'blood_ketone_data',
          indicatorValue: Number(measurementValue.value.height),
          parentKey: 'blood_ketone'
        }
      ]
    }
    saveReportData(param)
  } else if (state.checkRulesType == 'uric_acid') {
    param = {
      report: {
        reportId: updateId.value,
        empi: userInfo.value.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'uric_acid'
      },
      details: [
        {
          empi: userInfo.value.empi,
          indicatorKey: 'uric_acid_data',
          indicatorValue: Number(measurementValue.value.height),
          parentKey: 'uric_acid'
        }
      ]
    }
    saveReportData(param)
  } else if (state.checkRulesType == 'blood_fat') {
    param = {
      report: {
        reportId: updateId.value,
        empi: userInfo.value.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'blood_fat'
      },
      details: [
        {
          empi: userInfo.value.empi,
          indicatorKey: 'total_cholesterol',
          indicatorValue: Number(measurementValue.value.height),
          parentKey: 'blood_fat'
        },
        {
          empi: userInfo.value.empi,
          indicatorKey: 'tg',
          indicatorValue: Number(measurementValue.value.weight),
          parentKey: 'blood_fat'
        },

        {
          empi: userInfo.value.empi,
          indicatorKey: 'hdlc',
          indicatorValue: Number(measurementValue.value.pulse),
          parentKey: 'blood_fat'
        },
        {
          empi: userInfo.value.empi,
          indicatorKey: 'ldlc',
          indicatorValue: Number(measurementValue.value.fourValue),
          parentKey: 'blood_fat'
        }
      ]
    }
    saveReportData(param)
  } else if (state.checkRulesType == 'liver_function') {
    param = {
      report: {
        reportId: updateId.value,
        empi: userInfo.value.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'liver_function'
      },
      details: [
        {
          empi: userInfo.value.empi,
          indicatorKey: 'got',
          indicatorValue: Number(measurementValue.value.height),
          parentKey: 'liver_function'
        },
        {
          empi: userInfo.value.empi,
          indicatorKey: 'gpt',
          indicatorValue: Number(measurementValue.value.weight),
          parentKey: 'liver_function'
        },

        {
          empi: userInfo.value.empi,
          indicatorKey: 'ygt',
          indicatorValue: Number(measurementValue.value.pulse),
          parentKey: 'liver_function'
        }
      ]
    }
    saveReportData(param)
  }
  return true
}
const sureSleep = () => {
  uni.showLoading({
    title: '加载中'
  })

  if (new Date(state.wakeupDate).getTime() - new Date(state.sleepDate).getTime() <= 0) {
    uni.hideLoading()
    uni.showToast({
      title: '入睡时间需比醒来时间早',
      icon: 'none'
    })
    return false
  }

  if (
    parseFloat(
      timestampToHours(new Date(state.wakeupDate).getTime() - new Date(state.sleepDate).getTime())
    ) > 16
  ) {
    uni.hideLoading()
    uni.showToast({
      title: '入睡时间和醒来时间间隔过长，请重新选择',
      icon: 'none'
    })
    return false
  }

  console.log(state.sleepDate, state.wakeupDate)

  const data = {
    sleepTime: state.sleepDate + ':00',
    weekupTime: state.wakeupDate + ':00',
    sleepDuration: timestampToHours(
      new Date(state.wakeupDate).getTime() - new Date(state.sleepDate).getTime()
    )
  }
  let param = {}
  param = {
    id: updateId.value,
    paramValue: JSON.stringify(data),
    empi: userInfo.value.empi,
    collectTime: state.time + ':00',
    dataSource: 'MANUAL',
    paramKey: 'sleep'
  }
  newHealthDateSave(param)
  return true
}
// 将时间戳转换为小时
const timestampToHours = (timestamp: any) => {
  const differenceInHours = timestamp / (1000 * 60 * 60) // 转换为小时
  return differenceInHours.toFixed(2)
}
const oldHealthDataUpdate = async (param: any) => {
  state.isClick = true
  healthInfoUpdate(param)
    .then((res) => {
      uni.hideLoading()
      if (res.code == 0) {
        if (res.data == 'true') {
          show.value = false
          showSleep.value = false
          abnormalShow.value = true
        } else {
          uni.showToast({
            title: '提交成功',
            icon: 'none',
            duration: 2000
          })
          setTimeout(() => {
            show.value = false
            showSleep.value = false
            init()
          }, 2000)
        }
      }
    })
    .catch((err) => {
      state.isClick = false
    })
}
/// 新指标保存
const newHealthDateSave = (param: any) => {
  saveNewIndicator(param)
    .then((res) => {
      uni.hideLoading()
      if (res.code == 0) {
        if (res.data == true && state.type != 'water') {
          show.value = false
          showSleep.value = false
          abnormalShow.value = true
        } else {
          uni.showToast({
            title: '提交成功',
            icon: 'none',
            duration: 1500
          })
          setTimeout(() => {
            show.value = false
            showSleep.value = false
            init()
          }, 2000)
        }
      }
    })
    .catch((err) => {
      state.isClick = false
    })
}
// 保存报告
const saveReportData = (param: any) => {
  saveReport(param)
    .then((res) => {
      uni.hideLoading()
      if (res.code == 0) {
        if (res.data == 'true') {
          show.value = false
          showSleep.value = false
          abnormalShow.value = true
        } else {
          uni.showToast({
            title: '提交成功',
            icon: 'none',
            duration: 1500
          })
          setTimeout(() => {
            show.value = false
            showSleep.value = false
            init()
          }, 2000)
        }
      }
    })
    .catch((err) => {
      state.isClick = false
    })
}

const abnormalClose = () => {
  abnormalShow.value = false
  init()
}

const matchUnit = () => {
  switch (state.type) {
    case 'blood_ketone':
      return 'mmol/L'
    case 'uric_acid':
      return 'umol/L'
    case 'blood_fat':
      return 'mmol/L'
    case 'liver_function':
      return 'U/L'
    default:
      return ''
  }
}

const edit = (name: string, editItem: any) => {
  console.log('编辑', editItem)
  state.tabkeyboardShow = true
  state.slideRuleShow = true
  state.slideRuleType = ''
  state.slideRuleTypeDefault = false
  state.isClick = false
  state.time = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}').replace(/\//g, '-')
  message.value.currentScore = 50
  message.value.maxValue = 100
  state.checkRulesType = ''
  message.value.name = ''
  if (
    state.type == 'blood_ketone' ||
    state.type == 'blood_sugar' ||
    state.type == 'uric_acid' ||
    state.type == 'liver_function' ||
    state.type == 'blood_fat'
  ) {
    if (editItem.report.reportSource == '华为运动健康') {
      return false
    }
    updateId.value = editItem.report.reportId
    if (editItem.report.checkTime) {
      state.time = parseTime(
        new Date(editItem.report.checkTime).getTime(),
        '{y}-{m}-{d} {h}:{i}'
      ).replace(/\//g, '-')
    } else if (editItem.report.realTime) {
      state.time = parseTime(
        new Date(editItem.report.realTime).getTime(),
        '{y}-{m}-{d} {h}:{i}'
      ).replace(/\//g, '-')
    }
  } else {
    if (editItem.dataSource == '华为运动健康') {
      return false
    }
    updateId.value = editItem.id
    state.time = parseTime(new Date(editItem.collectTime).getTime(), '{y}-{m}-{d} {h}:{i}').replace(
      /\//g,
      '-'
    )
  }
  setTimeout(() => {
    if (name == 'bmi') {
      state.checkRulesType = 'BMI'
    } else if (name == 'sbp') {
      state.checkRulesType = 'blood_pressure'
    } else if (name == 'heart_rate') {
      state.checkRulesType = 'heart'
    } else if (name == 'spo2') {
      state.checkRulesType = 'blood_oxygen'
    } else {
      state.checkRulesType = name
    }
    show.value = true
  }, 10)
  message.value.unit = ''
  messageWeight.value.currentScore = 100
  messageWeight.value.maxValue = 150
  messageWeight.value.name = ''
  messageWeight.value.unit = ''
  messageThree.value.currentScore = 100
  messageThree.value.maxValue = 150
  messageThree.value.name = ''
  messageThree.value.unit = ''
  messageFour.value.currentScore = 100
  messageFour.value.maxValue = 150
  messageFour.value.name = ''
  messageFour.value.unit = ''
  measurementValue.value.height = 0
  measurementValue.value.weight = 0
  measurementValue.value.pulse = 0
  measurementValue.value.fourValue = 0
  state.bloodSugarActive = 0
  if (name == 'sleep') {
    showSleep.value = true
    state.sleepDate = parseTime(editItem.paramValue.sleepTime, '{y}-{m}-{d} {h}:{i}')
    state.wakeupDate = parseTime(editItem.paramValue.weekupTime, '{y}-{m}-{d} {h}:{i}')
  }
  if (name == 'bmi') {
    message.value.currentScore = JSON.stringify(editItem) !== '{}' ? editItem.height : 170
    message.value.init = JSON.stringify(editItem) !== '{}' ? editItem.height : 170
    measurementValue.value.height = JSON.stringify(editItem) !== '{}' ? editItem.height : 170
    message.value.maxValue = 250
    message.value.name = '身高'
    message.value.unit = 'cm'
    messageWeight.value.currentScore = JSON.stringify(editItem) !== '{}' ? editItem.weight : 65
    messageWeight.value.init = JSON.stringify(editItem) !== '{}' ? editItem.weight : 65
    measurementValue.value.weight = JSON.stringify(editItem) !== '{}' ? editItem.weight : 65
    messageWeight.value.maxValue = 200
    messageWeight.value.name = '体重'
    messageWeight.value.unit = 'kg'
  } else if (name == 'whr') {
    message.value.currentScore = JSON.stringify(editItem) !== '{}' ? editItem.waist : 85
    message.value.init = JSON.stringify(editItem) !== '{}' ? editItem.waist : 85
    measurementValue.value.height = JSON.stringify(editItem) !== '{}' ? editItem.waist : 85
    message.value.maxValue = 200
    message.value.name = '腰围'
    message.value.unit = 'cm'
    messageWeight.value.currentScore = JSON.stringify(editItem) !== '{}' ? editItem.hip : 100
    messageWeight.value.init = JSON.stringify(editItem) !== '{}' ? editItem.hip : 100
    measurementValue.value.weight = JSON.stringify(editItem) !== '{}' ? editItem.hip : 100
    messageWeight.value.maxValue = 200
    messageWeight.value.name = '臀围'
    messageWeight.value.unit = 'cm'
  } else if (name == 'sbp') {
    message.value.currentScore = JSON.stringify(editItem) !== '{}' ? editItem.sbp : 120
    message.value.init = JSON.stringify(editItem) !== '{}' ? editItem.sbp : 120
    measurementValue.value.height = JSON.stringify(editItem) !== '{}' ? editItem.sbp : 120
    message.value.maxValue = 300
    message.value.name = '收缩压'
    message.value.unit = 'mmHg'
    messageWeight.value.currentScore = JSON.stringify(editItem) !== '{}' ? editItem.dbp : 80
    messageWeight.value.init = JSON.stringify(editItem) !== '{}' ? editItem.dbp : 80
    measurementValue.value.weight = JSON.stringify(editItem) !== '{}' ? editItem.dbp : 80
    messageWeight.value.maxValue = 300
    messageWeight.value.name = '舒张压'
    messageWeight.value.unit = 'mmHg'
    messageThree.value.currentScore = JSON.stringify(editItem) !== '{}' ? editItem.pulseRate : 75
    messageThree.value.init = JSON.stringify(editItem) !== '{}' ? editItem.pulseRate : 75
    measurementValue.value.pulse = JSON.stringify(editItem) !== '{}' ? editItem.pulseRate : 75
    messageThree.value.maxValue = 180
    messageThree.value.name = '脉搏'
    messageThree.value.unit = '次/分'
  } else if (name == 'heart_rate') {
    message.value.currentScore = JSON.stringify(editItem) !== '{}' ? editItem.heartRate : 75
    message.value.init = JSON.stringify(editItem) !== '{}' ? editItem.heartRate : 75
    measurementValue.value.height = JSON.stringify(editItem) !== '{}' ? editItem.heartRate : 75
    message.value.maxValue = 180
    message.value.name = '心率'
    message.value.unit = '次/分'
  } else if (name == 'blood_sugar') {
    message.value.currentScore = editItem ? editItem.details[0].indicatorValue : 5.5
    message.value.init = editItem ? editItem.details[0].indicatorValue : 5.5
    measurementValue.value.height = editItem ? editItem.details[0].indicatorValue : 5.5
    state.bloodSugarActive = bloodSugarList.findIndex(
      (el) =>
        el.name == editItem.details[0].indicatorName ||
        el.title == editItem.details[0].indicatorName
    )
    message.value.maxValue = 30
    message.value.name = '血糖'
    message.value.unit = 'mmol/L'
  } else if (name == 'spo2') {
    message.value.currentScore = JSON.stringify(editItem) !== '{}' ? editItem.spo2 : 97
    message.value.init = JSON.stringify(editItem) !== '{}' ? editItem.spo2 : 97
    measurementValue.value.height = JSON.stringify(editItem) !== '{}' ? editItem.spo2 : 97
    message.value.maxValue = 100
    message.value.name = '血氧饱和度'
    message.value.unit = '%'
  } else if (name == 'blood_ketone') {
    message.value.currentScore = editItem ? editItem.details[0].indicatorValue : 0.17
    message.value.init = editItem ? editItem.details[0].indicatorValue : 0.17
    measurementValue.value.height = editItem ? editItem.details[0].indicatorValue : 0.17
    message.value.maxValue = 4.0
    message.value.name = '血酮'
    message.value.unit = 'mmol/L'
  } else if (name == 'uric_acid') {
    message.value.currentScore = editItem ? editItem.details[0].indicatorValue : 200
    message.value.init = editItem ? editItem.details[0].indicatorValue : 200
    measurementValue.value.height = editItem ? editItem.details[0].indicatorValue : 200
    message.value.maxValue = 600
    message.value.name = '尿酸'
    message.value.unit = 'umol/L'
  } else if (name == 'water') {
    message.value.currentScore = editItem ? Math.round(Number(editItem.paramValue)) : 350
    message.value.init = editItem ? Math.round(Number(editItem.paramValue)) : 350
    measurementValue.value.height = editItem ? Math.round(Number(editItem.paramValue)) : 350
    message.value.maxValue = 4000
    message.value.name = '饮水'
    message.value.unit = 'ml'
  } else if (name == 'blood_fat') {
    message.value.currentScore =
      JSON.stringify(editItem) !== '{}' ? editItem.details[0].indicatorValue : 4.0
    message.value.init =
      JSON.stringify(editItem) !== '{}' ? editItem.details[0].indicatorValue : 4.0
    measurementValue.value.height =
      JSON.stringify(editItem) !== '{}' ? editItem.details[0].indicatorValue : 4.0
    message.value.maxValue = 6.0
    message.value.name = '总胆固醇'
    message.value.unit = 'mmol/L'

    messageWeight.value.currentScore =
      JSON.stringify(editItem) !== '{}' ? editItem.details[1].indicatorValue : 1.0
    messageWeight.value.init =
      JSON.stringify(editItem) !== '{}' ? editItem.details[1].indicatorValue : 1.0
    measurementValue.value.weight =
      JSON.stringify(editItem) !== '{}' ? editItem.details[1].indicatorValue : 1.0
    messageWeight.value.maxValue = 3.0
    messageWeight.value.name = '甘油三酯'
    messageWeight.value.unit = 'mmol/L'

    messageThree.value.currentScore =
      JSON.stringify(editItem) !== '{}' ? editItem.details[2].indicatorValue : 1.3
    messageThree.value.init =
      JSON.stringify(editItem) !== '{}' ? editItem.details[2].indicatorValue : 1.3
    measurementValue.value.pulse =
      JSON.stringify(editItem) !== '{}' ? editItem.details[2].indicatorValue : 1.3
    messageThree.value.maxValue = 3.0
    messageThree.value.name = '高密度脂蛋白'
    messageThree.value.unit = 'mmol/L'

    messageFour.value.init =
      JSON.stringify(editItem) !== '{}' ? editItem.details[3].indicatorValue : 3.0
    messageFour.value.currentScore =
      JSON.stringify(editItem) !== '{}' ? editItem.details[3].indicatorValue : 3.0
    measurementValue.value.fourValue =
      JSON.stringify(editItem) !== '{}' ? editItem.details[3].indicatorValue : 3.0
    messageFour.value.maxValue = 5.0
    messageFour.value.name = '低密度脂蛋白'
    messageFour.value.unit = 'mmol/L'
  } else if (name == 'liver_function') {
    message.value.currentScore =
      JSON.stringify(editItem) !== '{}' ? editItem.details[0].indicatorValue : 28
    message.value.init = JSON.stringify(editItem) !== '{}' ? editItem.details[0].indicatorValue : 28
    measurementValue.value.height =
      JSON.stringify(editItem) !== '{}' ? editItem.details[0].indicatorValue : 28
    message.value.maxValue = 60
    message.value.name = '谷草转氨酶'
    message.value.unit = 'U/L'

    messageWeight.value.currentScore =
      JSON.stringify(editItem) !== '{}' ? editItem.details[1].indicatorValue : 30
    messageWeight.value.init =
      JSON.stringify(editItem) !== '{}' ? editItem.details[1].indicatorValue : 30
    measurementValue.value.weight =
      JSON.stringify(editItem) !== '{}' ? editItem.details[1].indicatorValue : 30
    messageWeight.value.maxValue = 60
    messageWeight.value.name = '谷丙转氨酶'
    messageWeight.value.unit = 'U/L'

    messageThree.value.currentScore =
      JSON.stringify(editItem) !== '{}' ? editItem.details[2].indicatorValue : 26
    messageThree.value.init =
      JSON.stringify(editItem) !== '{}' ? editItem.details[2].indicatorValue : 26
    measurementValue.value.pulse =
      JSON.stringify(editItem) !== '{}' ? editItem.details[2].indicatorValue : 26
    messageThree.value.maxValue = 60
    messageThree.value.name = 'Y-谷氨酰转肽酶'
    messageThree.value.unit = 'U/L'
  }
}

const measuremenKey = (value) => {
  state.tabkeyboardShow = !state.tabkeyboardShow
  state.slideRuleShow = !state.slideRuleShow
  state.slideRuleType = value
  state.slideRuleTypeDefault = true
  if (value == 'slideRule') {
    if (state.checkRulesType == 'BMI') {
      if (Number(measurementValue.value.height) <= 250) {
        message.value.init = Math.round(Number(measurementValue.value.height))
        message.value.currentScore = Math.round(Number(measurementValue.value.height))
        measurementValue.value.height = Math.round(Number(measurementValue.value.height))
      } else {
        message.value.init = 250
        message.value.currentScore = 250
        measurementValue.value.height = 250
      }
      if (Number(measurementValue.value.weight) <= 200) {
        messageWeight.value.init = Math.round(Number(measurementValue.value.weight))
        messageWeight.value.currentScore = Math.round(Number(measurementValue.value.weight))
        measurementValue.value.weight = Math.round(Number(measurementValue.value.weight))
      } else {
        messageWeight.value.init = 200
        messageWeight.value.currentScore = 200
        measurementValue.value.weight = 200
      }
    } else if (state.checkRulesType == 'whr') {
      if (Number(measurementValue.value.height) <= 200) {
        message.value.init = Math.round(Number(measurementValue.value.height))
        message.value.currentScore = Math.round(Number(measurementValue.value.height))
        measurementValue.value.height = Math.round(Number(measurementValue.value.height))
      } else {
        message.value.init = 200
        message.value.currentScore = 200
        measurementValue.value.height = 200
      }
      if (Number(measurementValue.value.weight) <= 200) {
        messageWeight.value.init = Math.round(Number(measurementValue.value.weight))
        messageWeight.value.currentScore = Math.round(Number(measurementValue.value.weight))
        measurementValue.value.weight = Math.round(Number(measurementValue.value.weight))
      } else {
        messageWeight.value.init = 200
        messageWeight.value.currentScore = 200
        measurementValue.value.weight = 200
      }
    } else if (state.checkRulesType == 'heart') {
      if (Number(measurementValue.value.height) <= 180) {
        message.value.init = Math.round(Number(measurementValue.value.height))
        message.value.currentScore = Math.round(Number(measurementValue.value.height))
        measurementValue.value.height = Math.round(Number(measurementValue.value.height))
      } else {
        message.value.init = 180
        message.value.currentScore = 180
        measurementValue.value.height = 180
      }
    } else if (state.checkRulesType == 'blood_pressure') {
      if (Number(measurementValue.value.height) <= 300) {
        message.value.init = Math.round(Number(measurementValue.value.height))
        message.value.currentScore = Math.round(Number(measurementValue.value.height))
        measurementValue.value.height = Math.round(Number(measurementValue.value.height))
      } else {
        message.value.init = 300
        message.value.currentScore = 300
        measurementValue.value.height = 300
      }
      if (Number(measurementValue.value.weight) <= 300) {
        messageWeight.value.init = Number(measurementValue.value.weight)
        messageWeight.value.currentScore = Number(measurementValue.value.weight)
        measurementValue.value.weight = Number(measurementValue.value.weight)
      } else {
        messageWeight.value.init = 300
        messageWeight.value.currentScore = 300
        measurementValue.value.weight = 300
      }
      if (Number(measurementValue.value.pulse) <= 180) {
        messageThree.value.init = Number(measurementValue.value.pulse)
        messageThree.value.currentScore = Number(measurementValue.value.pulse)
        measurementValue.value.pulse = Number(measurementValue.value.pulse)
      } else {
        messageThree.value.init = 180
        messageThree.value.currentScore = 180
        measurementValue.value.pulse = 180
      }
    } else if (state.checkRulesType == 'blood_sugar') {
      if (Number(measurementValue.value.height) <= 30) {
        message.value.init = Number(measurementValue.value.height)
        message.value.currentScore = Number(measurementValue.value.height)
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        message.value.currentScore = 30
        measurementValue.value.height = 30
      }
    } else if (state.checkRulesType == 'blood_oxygen') {
      if (Number(measurementValue.value.height) <= 100) {
        message.value.init = Math.round(Number(measurementValue.value.height))
        message.value.currentScore = Math.round(Number(measurementValue.value.height))
        measurementValue.value.height = Math.round(Number(measurementValue.value.height))
      } else {
        message.value.init = 100
        message.value.currentScore = 100
        measurementValue.value.height = 100
      }
    } else if (state.checkRulesType == 'water') {
      if (Number(measurementValue.value.height) <= 4000) {
        message.value.init = Math.round(Number(measurementValue.value.height))
        message.value.currentScore = Math.round(Number(measurementValue.value.height))
        measurementValue.value.height = Math.round(Number(measurementValue.value.height))
      } else {
        message.value.init = 4000
        message.value.currentScore = 4000
        measurementValue.value.height = 4000
      }
    } else if (state.checkRulesType == 'blood_ketone') {
      if (Number(measurementValue.value.height) <= 4) {
        message.value.init = Number(measurementValue.value.height)
        message.value.currentScore = Number(measurementValue.value.height)
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        message.value.init = 4
        message.value.currentScore = 4
        measurementValue.value.height = 4
      }
    } else if (state.checkRulesType == 'uric_acid') {
      if (Number(measurementValue.value.height) <= 600) {
        message.value.init = Number(measurementValue.value.height)
        message.value.currentScore = Number(measurementValue.value.height)
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        message.value.init = 600
        message.value.currentScore = 600
        measurementValue.value.height = 600
      }
    } else if (state.checkRulesType == 'blood_fat') {
      if (Number(measurementValue.value.height) <= 6) {
        message.value.init = Number(measurementValue.value.height)
        message.value.currentScore = Number(measurementValue.value.height)
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        message.value.init = 6.0
        message.value.currentScore = 6.0
        measurementValue.value.height = 6.0
      }

      if (Number(measurementValue.value.weight) <= 3.0) {
        messageWeight.value.init = Number(measurementValue.value.weight)
        messageWeight.value.currentScore = Number(measurementValue.value.weight)
        measurementValue.value.weight = Number(measurementValue.value.weight)
      } else {
        messageWeight.value.init = 3.0
        messageWeight.value.currentScore = 3.0
        measurementValue.value.weight = 3.0
      }

      if (Number(measurementValue.value.pulse) <= 3.0) {
        messageThree.value.init = Number(measurementValue.value.pulse)
        messageThree.value.currentScore = Number(measurementValue.value.pulse)
        measurementValue.value.pulse = Number(measurementValue.value.pulse)
      } else {
        messageThree.value.init = 3.0
        messageThree.value.currentScore = 3.0
        measurementValue.value.pulse = 3.0
      }

      if (Number(measurementValue.value.fourValue) <= 5.0) {
        messageFour.value.init = Number(measurementValue.value.fourValue)
        messageFour.value.currentScore = Number(measurementValue.value.fourValue)
        measurementValue.value.fourValue = Number(measurementValue.value.fourValue)
      } else {
        messageFour.value.init = 5.0
        messageFour.value.currentScore = 5.0
        measurementValue.value.fourValue = 5.0
      }
    } else if (state.checkRulesType == 'liver_function') {
      if (Number(measurementValue.value.height) <= 60) {
        message.value.init = Number(measurementValue.value.height)
        message.value.currentScore = Number(measurementValue.value.height)
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        message.value.init = 60
        message.value.currentScore = 60
        measurementValue.value.height = 60
      }
      if (Number(measurementValue.value.weight) <= 60) {
        messageWeight.value.init = Number(measurementValue.value.weight)
        messageWeight.value.currentScore = Number(measurementValue.value.weight)
        measurementValue.value.weight = Number(measurementValue.value.weight)
      } else {
        messageWeight.value.init = 60
        messageWeight.value.currentScore = 60
        measurementValue.value.weight = 60
      }

      if (Number(measurementValue.value.pulse) <= 60) {
        messageThree.value.init = Number(measurementValue.value.pulse)
        messageThree.value.currentScore = Number(measurementValue.value.pulse)
        measurementValue.value.pulse = Number(measurementValue.value.pulse)
      } else {
        messageThree.value.init = 60
        messageThree.value.currentScore = 60
        measurementValue.value.pulse = 60
      }
    }
  } else if (value == 'keyboard') {
    if (state.checkRulesType == 'blood_sugar') {
      if (Number(measurementValue.value.height) <= 30) {
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        measurementValue.value.height = 30
      }
    } else if (state.checkRulesType == 'water') {
      if (Number(measurementValue.value.height) <= 4000) {
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        measurementValue.value.height = 4000
      }
    } else if (state.checkRulesType == 'blood_ketone') {
      if (Number(measurementValue.value.height) <= 4) {
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        measurementValue.value.height = 4
      }
    } else if (state.checkRulesType == 'uric_acid') {
      if (Number(measurementValue.value.height) <= 600) {
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        measurementValue.value.height = 600
      }
    } else if (state.checkRulesType == 'blood_fat') {
      if (Number(measurementValue.value.height) <= 6) {
        message.value.currentScore = Number(measurementValue.value.height)
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        message.value.currentScore = 6.0
        measurementValue.value.height = 6.0
      }

      if (Number(measurementValue.value.weight) <= 3.0) {
        messageWeight.value.currentScore = Number(measurementValue.value.weight)
        measurementValue.value.weight = Number(measurementValue.value.weight)
      } else {
        messageWeight.value.currentScore = 3.0
        measurementValue.value.weight = 3.0
      }

      if (Number(measurementValue.value.pulse) <= 3.0) {
        messageThree.value.currentScore = Number(measurementValue.value.pulse)
        measurementValue.value.pulse = Number(measurementValue.value.pulse)
      } else {
        messageThree.value.currentScore = 3.0
        measurementValue.value.pulse = 3.0
      }

      if (Number(measurementValue.value.fourValue) <= 5.0) {
        messageFour.value.currentScore = Number(measurementValue.value.fourValue)
        measurementValue.value.fourValue = Number(measurementValue.value.fourValue)
      } else {
        messageFour.value.currentScore = 5.0
        measurementValue.value.fourValue = 5.0
      }
    } else if (state.checkRulesType == 'liver_function') {
      if (Number(measurementValue.value.height) <= 60) {
        message.value.currentScore = Number(measurementValue.value.height)
        measurementValue.value.height = Number(measurementValue.value.height)
      } else {
        message.value.currentScore = 60
        measurementValue.value.height = 60
      }
      if (Number(measurementValue.value.weight) <= 60) {
        messageWeight.value.currentScore = Number(measurementValue.value.weight)
        measurementValue.value.weight = Number(measurementValue.value.weight)
      } else {
        messageWeight.value.currentScore = 60
        measurementValue.value.weight = 60
      }

      if (Number(measurementValue.value.pulse) <= 60) {
        messageThree.value.currentScore = Number(measurementValue.value.pulse)
        measurementValue.value.pulse = Number(measurementValue.value.pulse)
      } else {
        messageThree.value.currentScore = 60
        measurementValue.value.pulse = 60
      }
    }
  }
}
const childEvent = (param) => {
  if (
    param &&
    (param.name == '身高' ||
      param.name == '腰围' ||
      param.name == '收缩压' ||
      param.name == '心率' ||
      param.name == '总胆固醇' ||
      param.name == '谷草转氨酶')
  ) {
    measurementValue.value.height = param.currentSwiper
    message.value.currentScore = param.currentSwiper
  } else if (
    param &&
    (param.name == '体重' ||
      param.name == '臀围' ||
      param.name == '舒张压' ||
      param.name == '甘油三酯' ||
      param.name == '谷丙转氨酶')
  ) {
    measurementValue.value.weight = param.currentSwiper
    messageWeight.value.currentScore = param.currentSwiper
  } else if (
    (param && param.name == '脉搏') ||
    param.name == '高密度脂蛋白' ||
    param.name == 'Y-谷氨酰转肽酶'
  ) {
    measurementValue.value.pulse = param.currentSwiper
    messageThree.value.currentScore = param.currentSwiper
  } else if (param && param.name == '血糖') {
    measurementValue.value.height = param.currentSwiper
    message.value.currentScore = param.currentSwiper
  } else if (param && param.name == '血氧饱和度') {
    measurementValue.value.height = param.currentSwiper
    message.value.currentScore = param.currentSwiper
  } else if (param && param.name == '饮水') {
    measurementValue.value.height = param.currentSwiper
    message.value.currentScore = param.currentSwiper
  } else if (param && param.name == '血酮') {
    measurementValue.value.height = param.currentSwiper
    message.value.currentScore = param.currentSwiper
  } else if (param && param.name == '尿酸') {
    measurementValue.value.height = param.currentSwiper
    message.value.currentScore = param.currentSwiper
  } else if (param && param.name == '低密度脂蛋白') {
    measurementValue.value.fourValue = param.currentSwiper
    messageFour.value.currentScore = param.currentSwiper
  }
}

const getSleepTimes = (value: string) => {
  const sleepTimes = value.split('.')
  const hour = Number(sleepTimes[0])
  if (sleepTimes[1]) {
    const minute = Math.round(Number('0.' + sleepTimes[1]) * 60)
    return `${hour}小时${minute > 10 ? minute : '0' + minute}分`
  } else {
    return `${hour}小时`
  }
}
const closeDateTime = () => {
  show.value = true
  state.tabkeyboardShow = true
  if (state.slideRuleShow == true) {
    state.slideRuleShow = !state.slideRuleShow
    setTimeout(() => {
      state.slideRuleShow = !state.slideRuleShow
    }, 20)
  }
  dateShow.value = false
}
const confirmDateTime = () => {
  show.value = true
  dateShow.value = false
  if (state.slideRuleShow == true) {
    state.slideRuleShow = !state.slideRuleShow
    setTimeout(() => {
      state.slideRuleShow = !state.slideRuleShow
    }, 20)
  }
  if (state.datetimeNew) {
    state.time = state.datetimeNew.replace(/\//g, '-')
  } else {
    state.time = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}').replace(/\//g, '-')
  }
}
const changeFun = (item) => {
  const data = parseTime(new Date(item.value).getTime(), '{y}-{m}-{d} {h}:{i}')
  state.datetimeNew = data
}
const goit = () => {
  measurementShow.value = false
  if (state.slideRuleShow == true) {
    state.slideRuleShow = !state.slideRuleShow
    setTimeout(() => {
      state.slideRuleShow = !state.slideRuleShow
    }, 20)
  }
  show.value = true
}
const close = () => {
  show.value = false
  showSleep.value = false
}
const handleClick = (item: any, index: number, totalItem: any, totalIndex: any) => {
  console.log('删除id', item)
  if (state.type == 'bmi') {
    uni.showToast({
      title: '不能删除体重数据!',
      icon: 'none'
    })
    let delIndex = 0
    for (let i = 0; i < totalIndex; i++) {
      delIndex += state.taskList[i].list.length
    }
    swipeRef.value[delIndex + index].closeAll()
    deleteIndex.value = delIndex + index
    return
  }
  if (
    (item && item.dataSource == '华为运动健康') ||
    (item.report && item.report.reportSource == '华为运动健康')
  ) {
    uni.showToast({
      title: '不能删除华为同步数据!',
      icon: 'none'
    })
    if (
      state.type == 'water' ||
      state.type == 'bmi' ||
      state.type == 'whr' ||
      state.type == 'heart_rate' ||
      state.type == 'blood_oxygen' ||
      state.type == 'blood_pressure'
    ) {
      let delIndex = 0
      for (let i = 0; i < totalIndex; i++) {
        if (state.type == 'water') {
          delIndex += state.taskList[i].drinkList.length
        } else {
          delIndex += state.taskList[i].list.length
        }
      }
      swipeRef.value[delIndex + index].closeAll()
      deleteIndex.value = delIndex + index
    } else {
      swipeRef.value[index].closeAll()
      deleteIndex.value = index
    }
    return
  }
  if (
    state.type == 'blood_ketone' ||
    state.type == 'blood_sugar' ||
    state.type == 'uric_acid' ||
    state.type == 'liver_function' ||
    state.type == 'blood_fat'
  ) {
    updateId.value = item.report.id
  } else {
    updateId.value = item.id
  }
  state.deleteShow = true
}
const deleteSignsInfo = () => {
  let deleteParam = [
    {
      id: updateId.value,
      paramKey: state.type
    }
  ]
  signsInfoDelete(deleteParam).then((res) => {
    state.deleteShow = false
    uni.showToast({
      title: '删除成功',
      icon: 'none',
      duration: 2000
    })
    init()
  })
}
const cancel = () => {
  state.deleteShow = false
  swipeRef.value[deleteIndex.value].closeAll()
}
</script>

<style lang="scss" scoped>
.wraps {
  min-height: 100vh;
  padding-bottom: 64rpx;

  .content {
    width: calc(100% - 64rpx);
    margin-left: 32rpx;

    ::v-deep .u-swipe-action-item {
      margin-bottom: 24rpx !important;
      border-radius: 12rpx !important;
    }

    ::v-deep .u-swipe-action-item__right__button__wrapper {
      font-size: 24rpx;
      font-weight: 400;
      color: #fff;
      border-radius: 0 12rpx 12rpx 0 !important;
    }
    ::v-deep .drink-item {
      .u-swipe-action {
        .u-swipe-action-item {
          &:nth-last-child(1) {
            .min-water {
              border: none;
            }
          }
        }
      }
    }
    .nodate {
      text-align: center;
      padding-top: 240rpx;

      .img {
        display: inline-block;
        width: 320rpx;
        height: 240rpx;
      }

      .nodate_text {
        .name {
          display: block;
          margin-top: 10rpx;
          font-size: 28rpx;
          color: #666;
          text-align: center;
        }
      }
    }
  }

  ::v-deep .u-popup {
    .u-popup__content {
      overflow: hidden;

      .abnormalContent {
        width: 80vw;

        .title {
          padding: 40rpx 32rpx 0;
          font-size: 34rpx;
          font-weight: 700;
          color: #1d2129;
          text-align: center;
        }

        .content {
          display: block;
          padding: 15rpx 32rpx 40rpx;
          font-size: 30rpx;
          color: #4e5969;
          text-align: center;
          border-bottom: 2rpx solid #e5e6eb;
        }

        .know {
          height: 88rpx;
          font-size: 32rpx;
          line-height: 88rpx;
          color: #00d1b6;
          text-align: center;
        }
      }
    }

    .popup-wrap {
      padding-bottom: calc(160rpx + constant(safe-area-inset-bottom));
      padding-bottom: calc(160rpx + env(safe-area-inset-bottom));

      .title {
        padding: 32rpx;
        font-size: 32rpx;
        font-weight: 700;
        text-align: center;
        border-bottom: 1rpx solid #e5e6eb;
      }

      .popupContent {
        padding: 32rpx;
        font-size: 30rpx;
        color: #222;
      }
      .scroll-slide {
        max-height: 800rpx;
      }

      .tabKey {
        position: relative;
        padding: 20rpx 30rpx 30rpx;

        .name {
          font-size: 30rpx;
          font-weight: 700;
          color: #00d1b6;

          &.on {
            color: #fff;
          }
        }

        .keyboard {
          position: absolute;
          top: 50%;
          right: 30rpx;
          transform: translateY(-50%);

          .img {
            display: inline-block;
            font-size: 36rpx;
            color: #999;
            vertical-align: middle;
            width: 36rpx;
            height: 36rpx;
          }

          .key {
            display: inline-block;
            margin-left: 10rpx;
            font-size: 28rpx;
            color: #222;
            vertical-align: middle;
          }
        }
      }

      .listWraps {
        width: calc(100% - 32rpx);
        height: 118rpx;
        margin: 32rpx 0rpx 0 32rpx;
        // display: flex;
        // flex-direction: row;
        // align-items: center;
        // justify-content: space-between;

        .scroll-view_H {
          width: 100%;
          white-space: nowrap;
        }

        .item {
          display: inline-block;
          // display: flex;
          width: 112rpx;
          height: 110rpx;
          margin-right: 16rpx;
          text-align: center;
          background: #fafafa;
          border-radius: 12rpx;

          // &:nth-last-child(1) {
          //   margin-right: 0;
          // }

          .name {
            display: block;
            width: 100%;
            margin: 10rpx 0 8rpx;
            font-size: 28rpx;
            font-weight: 600;
            color: #333;
            text-align: center;

            // &:nth-child(1) {
            //   display: block;
            //   font-size: 20rpx;
            //   font-weight: 700;
            //   color: #333;
            // }
          }

          .time-title {
            display: block;
            width: 100%;
            font-size: 26rpx;
            font-weight: 400;
            color: #666;
            text-align: center;
          }

          &.on {
            background: #00d1b6;

            .name {
              color: #fff;
            }

            .time-title {
              color: #fff;
            }

            // &::after {
            //   position: absolute;
            //   bottom: -8rpx;
            //   left: 50%;
            //   width: 0;
            //   height: 0;
            //   content: '';
            //   border-top: 10rpx solid #00d1b6;
            //   border-right: 10rpx solid transparent;
            //   border-left: 10rpx solid transparent;
            //   transform: translateX(-50%);
            // }
          }
        }
      }

      .btn {
        height: 88rpx;
        margin: 0 32rpx;
        font-size: 32rpx;
        font-weight: 700;
        line-height: 88rpx;
        color: #fff;
        text-align: center;
        background: #00d1b6;
        border-radius: 44rpx;
      }

      .fixedBtn {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 24rpx 0;
        padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
        padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
        color: #fff;
        text-align: center;
        background: #fff;
        border-top: 1rpx solid #e5e6eb;

        .name {
          display: inline-block;
          width: calc(100% - 60rpx);
          padding: 22rpx 0;
          margin: 0 30rpx;
          font-size: 32rpx;
          background: #00d1b6;
          border-radius: 50rpx;
        }
      }

      .measure {
        display: inline-block;
        width: 100%;
        padding-bottom: 30rpx;
        background: #fff;

        .numWrap {
          display: grid;
          grid-template-columns: repeat(2, 1fr);
          margin: 20rpx 30rpx 0;
          text-align: center;
          background: #fafafa;
          border-radius: 4rpx;

          .item {
            display: inline-block;
            // width: 33.3%;
            height: 200rpx;
            padding: 10rpx 0 0rpx;
            margin: 0;
            vertical-align: middle;

            .value {
              display: block;
              width: 100%;
              padding: 20rpx 0 8rpx;
              font-size: 48rpx;
              color: #00d1b6;
              text-align: center;
              background: #fafafa;
              border: 0;
            }

            .wraps {
              padding: 10rpx 0;
              margin: 0 20rpx;
              font-size: 30rpx;
              color: #00d1b6;
              text-align: center;
              border-top: 1rpx solid #00d1b6;

              .name {
                display: inline-block;
                vertical-align: middle;

                &:nth-child(1) {
                  margin-right: 8rpx;
                }
              }
            }
          }
        }
      }

      .measureTime {
        position: relative;
        display: flex;
        justify-content: space-between;
        padding: 32rpx 0;
        margin: 0 32rpx;

        .name {
          font-size: 30rpx;
          font-weight: 700;
          color: #222;
        }

        .time {
          min-width: 200rpx;
          font-size: 30rpx;
          font-weight: 400;
          color: #222;
          text-align: right;

          .titles {
            display: inline-block;
            vertical-align: middle;
          }

          .img {
            display: inline-block;
            width: 30rpx;
            height: 30rpx;
            vertical-align: middle;
          }
        }
      }

      .sleepTime {
        padding: 32rpx;
        margin-bottom: 24rpx;
        background: #fafafa;
        border: 1rpx solid #e5e6eb;
        border-radius: 16rpx;
      }

      .measureDetail {
        margin: 0 32rpx;
        font-size: 26rpx;
        color: #999;

        .item {
          display: block;

          &:nth-child(2) {
            margin-top: 10rpx;
          }
        }
      }

      .content {
        position: relative;

        .contentWrap {
          margin: 0 32rpx;

          .contentItem {
            margin-top: 32rpx;
            font-size: 32rpx;
            color: #222;
          }

          .img {
            display: block;
            width: 100%;
            height: auto;
            margin-top: 30rpx;
          }
        }

        .fixedBtn {
          position: fixed;
          bottom: 0;
          left: 0;
          width: 100%;
          padding: 24rpx 0;
          padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
          padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
          color: #fff;
          text-align: center;
          background: #fff;
          border-top: 1rpx solid #fff;

          p {
            padding: 22rpx 0;
            margin: 0 30rpx;
            font-size: 32rpx;
            background: #02bcc3;
            border-radius: 50rpx;
          }
        }
      }
    }

    .u-popup__content__close {
      top: 40rpx;

      .uicon-close {
        font-size: 32rpx !important;
        line-height: 32rpx !important;
      }
    }
  }

  ::v-deep
    .u-popup
    .u-slide-up-enter-to
    .u-picker
    .u-picker__view__column
    .u-picker__view__column__item {
    line-height: 34px !important;
  }

  ::v-deep .u-popup .u-slide-up-enter-active {
    overflow: hidden;
    border-top-left-radius: 32rpx !important;
    border-top-right-radius: 32rpx !important;

    .u-toolbar {
      .u-toolbar__wrapper__confirm {
        color: #00d1b6 !important;
      }
    }
  }

  ::v-deep .u-popup .u-slide-up-enter-to .u-picker .u-picker__view {
    height: 400px !important;
  }

  ::v-deep .u-safe-area-inset-bottom {
    padding-bottom: 0 !important;
  }
}

.food-type {
  display: inline-block;
  padding: 4rpx 20rpx 2rpx;
  margin-left: 16rpx;
  font-size: 24rpx;
  font-weight: 400;
  color: #666;
  background: #f5f5f5;
  border-radius: 20rpx 4rpx;
}

.source {
  font-size: 26rpx;
  color: #999;
}
</style>
